@extends('layouts.admin')
@section('pageTitle', '新建触发')
@inject('storeService', 'App\App\Services\StorageService')
@section('style')
    <style>

        /*meiyun*/
        .mgud{
            margin: 20px auto;
        }
        .mgb10{
            margin-bottom: 10px;
        }
        .mgr30{
            margin-right: 30px;
        }
        /*.main-panel{*/
            /*overflow: auto;*/
        /*}*/

        .card form [class*="col-"]:first-child {
            padding: 0 6px;
        }

        .card form [class*="col-"]:last-child {
            padding: 0 6px;
        }

        .template-active-img img {
            width: 100%;
            height: auto;
            overflow: hidden;
        }
        .template-active-img .user-template-btn {
            position: absolute;
            bottom: 20px;
            left: 50%;
            margin-left: -22px;
        }
        .template-active-img .template-qrcode {
            width: 100%;
            height: 100%;
            position: absolute;
            left: 0;
            top: 0;
            background: rgba(0,0,0,.5);
            display: none;
        }
        .template-active-img:hover .template-qrcode{
            display:block
        }
    </style>
@endsection
@section('content')
    <div class="main-panel">
        <div class="content">
            <div class="container-fluid">

                <div class="row">
                    <div class="col-md-12">
                        <div class="card">
                            <div class="content content-full-width">

                                <form id="wizardForm" class="form-horizontal" data-back="/web/activityTrigger/index" method="post"  action="/web/activityTrigger/modify" >
                                    <input type="hidden" name="id" value="{{$triggerData['id']}}" />
                                    <div class="row">
                                        <!--左侧手机演示图-->
                                        <div class="col-xs-4 app">
                                            <div class="phone-view">
                                                <div class="app-view">
                                                    <div class="touch-app-mainC">
                                                        <!--大图-->
                                                        <div class="touch-app-big-image displayable">
                                                            <img src="{{$storeService->tomedia(json_decode($triggerData['big_img'],true)[0])}}"/>
                                                        </div>
                                                        <!--小图-->
                                                        <div class="touch-app-small-moveDiv">
                                                            <div class="touch-app-small-image"></div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                        <!--右侧功能配置图-->
                                        <div class="col-xs-8">
                                            <div class="row">
                                                <div class="col-sm-12">
                                                    <!--规则名称-->
                                                    <div class="form-group">
                                                        <label class="col-sm-2 control-label">规则名称</label>
                                                        <div class="col-sm-7">
                                                            <input class="form-control point-rule-name" type="text"
                                                                   placeholder="请输入规则名称，最多支持20个字符"
                                                                   {{--maxlength=20--}}
                                                                   name="rule_name"
                                                                   {{--required="required"--}}
                                                                   value="{{$triggerData['rule_name']}}"
                                                            />
                                                        </div>
                                                    </div>
                                                    <!--投放活动-->
                                                    <div class="form-group">
                                                        <label class="col-sm-2 control-label">投放活动</label>
                                                        <div class="col-sm-7">
                                                            <div class="input-group">
                                                                <input type="hidden" name="act_id" value="{{$triggerData['act_id']}}"/>
                                                                <input type="text" class="form-control" name="act_name" value="{{$triggerData['act_name']}}" onclick="show_activity_deliveries(this)" placeholder="+添加活动" aria-label="添加活动">
                                                                <div class="input-group-btn">
                                                                    <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">@if($triggerData['act_type'] == 1)列表活动 @else 自有活动 @endif <span class="caret"></span></button>
                                                                    <input type="hidden" class="form-control" value="{{$triggerData['act_type']}}" data-name="act_type" name="act_type" >
                                                                    <ul class="dropdown-menu dropdown-menu-right">
                                                                        <li><a href="#" data-val="{{\App\Models\ActivityTrigger\ActivityTrigger::ACTIVITY_TRIGGER_ACT_TYPE_LIST}}" onclick="actType(this)">列表活动</a></li>
                                                                        <li><a href="#" data-val="{{\App\Models\ActivityTrigger\ActivityTrigger::ACTIVITY_TRIGGER_ACT_TYPE_SELF}}" onclick="actType(this)">自由活动</a></li>
                                                                    </ul>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <!--选择平台-->
                                                    <div class="form-group">
                                                        <label class="col-sm-2 control-label">选择平台</label>
                                                        <div class="col-sm-7">
                                                            <label class="checkbox-inline">
                                                                <input type="checkbox" name="platform[]" class="" value="{{\App\Models\ActivityTrigger\ActivityTrigger::ACTIVITY_TRIGGER_PLATFORM_JS}}" @if(($triggerData['platform'] & \App\Models\ActivityTrigger\ActivityTrigger::ACTIVITY_TRIGGER_PLATFORM_JS) == \App\Models\ActivityTrigger\ActivityTrigger::ACTIVITY_TRIGGER_PLATFORM_JS) checked @endif> Js
                                                            </label>
                                                            <label class="checkbox-inline">
                                                                <input type="checkbox" name="platform[]" class="" value="{{\App\Models\ActivityTrigger\ActivityTrigger::ACTIVITY_TRIGGER_PLATFORM_IOS}}" @if(($triggerData['platform'] & \App\Models\ActivityTrigger\ActivityTrigger::ACTIVITY_TRIGGER_PLATFORM_IOS) == \App\Models\ActivityTrigger\ActivityTrigger::ACTIVITY_TRIGGER_PLATFORM_IOS) checked @endif> iOS
                                                            </label>
                                                            <label class="checkbox-inline">
                                                                <input type="checkbox" name="platform[]" class="" value="{{\App\Models\ActivityTrigger\ActivityTrigger::ACTIVITY_TRIGGER_PLATFORM_ANDROID}}" @if(($triggerData['platform'] & \App\Models\ActivityTrigger\ActivityTrigger::ACTIVITY_TRIGGER_PLATFORM_ANDROID) == \App\Models\ActivityTrigger\ActivityTrigger::ACTIVITY_TRIGGER_PLATFORM_ANDROID) checked @endif> Android
                                                            </label>
                                                        </div>
                                                    </div>
                                                    <!--触发形式-->
                                                    <div class="form-group">
                                                        <label class="col-sm-2 control-label">触发形式</label>
                                                        <div class="col-sm-7">
                                                            <label class="radio-inline">
                                                                <input type="radio" name="show_img" class="touch-put-small-picture" value="{{\App\Models\ActivityTrigger\ActivityTrigger::ACTIVITY_TRIGGER_SMALL_IMG}}" @if($triggerData['show_img'] == \App\Models\ActivityTrigger\ActivityTrigger::ACTIVITY_TRIGGER_SMALL_IMG) checked @endif> 小图
                                                            </label>
                                                            <label class="radio-inline">
                                                                <input type="radio" name="show_img" class="touch-put-big-picture" value="{{\App\Models\ActivityTrigger\ActivityTrigger::ACTIVITY_TRIGGER_BIG_IMG}}" @if($triggerData['show_img'] == \App\Models\ActivityTrigger\ActivityTrigger::ACTIVITY_TRIGGER_BIG_IMG) checked @endif> 大图
                                                            </label>
                                                            <label class="radio-inline">
                                                                <input type="radio" name="show_img" class="touch-put-no-picture" value="{{\App\Models\ActivityTrigger\ActivityTrigger::ACTIVITY_TRIGGER_NO_IMG}}" @if($triggerData['show_img'] == \App\Models\ActivityTrigger\ActivityTrigger::ACTIVITY_TRIGGER_NO_IMG) checked @endif> 无图
                                                            </label>
                                                        </div>
                                                    </div>
                                                    <!--触发形式选择后的图像展示-->
                                                    <!--小图-->
                                                    <div class="touch-small-picture">
                                                        <div class="form-group">
                                                            <label class="col-sm-2 control-label">图标样式</label>
                                                            <div class="col-sm-7">
                                                                <ul class="touch-small-ico-ul small-ico-ul">
                                                                    <li class="touch-small-ico-li touch-ico-border">
                                                                        <img src="http://cloud-activity-test.oss-cn-shanghai.aliyuncs.com/images/trigger_icon2.png" id="0">
                                                                        <input type="hidden" name="small_img[]" value="alioss://images/trigger_icon2.png" />
                                                                    </li>
                                                                    <li class="touch-small-ico-li">
                                                                        <img src="http://cloud-activity-test.oss-cn-shanghai.aliyuncs.com/images/trigger_icon3.png" id="1">
                                                                        <input type="hidden" name="small_img[]" value="alioss://images/trigger_icon3.png" />
                                                                    </li>
                                                                    <li class="touch-small-ico-li">
                                                                        <img src="http://cloud-activity-test.oss-cn-shanghai.aliyuncs.com/images/trigger_icon4.png" id="2">
                                                                        <input type="hidden" name="small_img[]" value="alioss://images/trigger_icon4.png" />
                                                                    </li>
                                                                    @if(!empty($triggerData['small_img']) && is_array(json_decode($triggerData['small_img'])))
                                                                    @foreach(json_decode($triggerData['small_img']) as $key=>$val)
                                                                        @if($key > 2 )
                                                                        <li class="touch-small-ico-li">
                                                                            <img src="{{$storeService->tomedia($val)}}" >
                                                                            <input type="hidden" name="small_img[]"  value="{{$val}}" />
                                                                        </li>
                                                                        @endif
                                                                    @endforeach
                                                                    @endif
                                                                    <div class="touch-ico-add touch-ico-add-small" data-toggle="modal" data-target="#touch-upload-modal">
                                                                        +
                                                                    </div>
                                                                </ul>
                                                                <input type="hidden" name="checked_small_img" class="checked_small_img" value="{{$triggerData['checked_small_img']}}" />
                                                            </div>
                                                        </div>
                                                        <div class="row">
                                                            <div class="col-sm-9 col-sm-offset-2">
                                                                <div class="form-group">
                                                                    <label class="control-label">100 * 100像素，支持GIF，PNG，JPG格式，建议小于200KB。</label>
                                                                </div>
                                                            </div>
                                                        </div>
                                                        <div class="form-group">
                                                            <label class="col-sm-2 control-label">图标位置</label>
                                                            <div class="col-sm-7" style="padding-top: 7px">
                                                                拖动图标到自定义的位置（距离顶部：<span class="touch-ico-top">@if($triggerData['totop']){{$triggerData['totop']}}@else 0 @endif</span>％；距离左侧：<span class="touch-ico-left">@if($triggerData['toleft']){{$triggerData['toleft']}}@else 0 @endif</span>％）
                                                                <input type="hidden" class="totop" name="totop" value="{{$triggerData['totop']}}" />
                                                                <input type="hidden" class="toleft" name="toleft" value="{{$triggerData['toleft']}}" />
                                                            </div>
                                                        </div>
                                                    </div>

                                                    <!--大图-->
                                                    <div class="touch-big-picture displayable">
                                                        <div class="form-group ">
                                                            <label class="col-sm-2 control-label">图标样式</label>
                                                            <div class="col-sm-7">
                                                                <ul class="touch-small-ico-ul big-ico-ul">
                                                                    <li class="touch-small-ico-li touch-ico-border">

                                                                        <img src="http://cloud-activity-test.oss-cn-shanghai.aliyuncs.com/images/trigger_icon_big.png" id="0"/>
                                                                    </li>
                                                                    <li class="touch-small-ico-li">
                                                                        <img src="http://cloud-activity-test.oss-cn-shanghai.aliyuncs.com/images/trigger_icon_big.png" id="0">
                                                                        <input type="hidden" name="big_img[]" value="alioss://images/trigger_icon_big.png" />

                                                                    </li>
                                                                    @if(!empty($triggerData['big_img']) && is_array(json_decode($triggerData['big_img'])))
                                                                    @foreach(json_decode($triggerData['big_img']) as $key=>$val)
                                                                        @if($key > 0 )
                                                                        <li class="touch-small-ico-li">
                                                                            <img src="{{$storeService->tomedia($val)}}" >
                                                                            <input type="hidden" name="big_img[]" value="{{$val}}"  />
                                                                        </li>
                                                                        @endif
                                                                    @endforeach
                                                                    @endif
                                                                    <div class="touch-ico-add touch-ico-add-big" data-toggle="modal" data-target="#touch-upload-modal">
                                                                        +
                                                                    </div>
                                                                </ul>
                                                                <input type="hidden" name="checked_big_img" class="checked_big_img" value="{{$triggerData['checked_big_img']}}" />
                                                            </div>
                                                        </div>
                                                        <div class="row">
                                                            <div class="col-sm-9 col-sm-offset-2">
                                                                <div class="form-group">
                                                                    <label class="control-label">500* 700像素，支持GIF，PNG，JPG格式，建议小于200KB。</label>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>

                                                    <!--悬浮时间-->
                                                    <div class="form-group">
                                                        <label class="col-sm-2 control-label">悬浮时间</label>
                                                        <div class="col-sm-7">
                                                            <div class="row">
                                                                <div class="col-sm-6">
                                                                    <select name="float_type"  class="form-control touch-select-float-time">
                                                                        <option value="{{\App\Models\ActivityTrigger\ActivityTrigger::ACTIVITY_TRIGGER_FLOAT_LONG}}" @if($triggerData['float_type'] == \App\Models\ActivityTrigger\ActivityTrigger::ACTIVITY_TRIGGER_FLOAT_LONG) selected @endif >一直存在</option>
                                                                        <option value="{{\App\Models\ActivityTrigger\ActivityTrigger::ACTIVITY_TRIGGER_FLOAT_TIMING}}" @if($triggerData['float_type'] == \App\Models\ActivityTrigger\ActivityTrigger::ACTIVITY_TRIGGER_FLOAT_TIMING) selected @endif >定时消失</option>
                                                                    </select>
                                                                </div>
                                                                <div class="col-sm-6 input-group touch-input-float-time  @if($triggerData['float_type'] == 1) displayable @endif ">
                                                                   <input class="form-control" type="number" min="1" name="float_time" value="{{$triggerData['float_time']}}"/>
                                                                    <div class="input-group-addon">秒</div>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <!--触发时间-->
                                                    <div class="form-group">
                                                        <label class="col-sm-2 control-label">触发时间</label>
                                                        <div class="col-sm-7">
                                                            <div class="row service-charges">
                                                                <div class="col-sm-5 service-charges-name service-charges-name-0" style="padding-left: 15px;">
                                                                    <input type="text" placeholder="开始时间" value="{{date('Y-m-d H:i:s',$triggerData['begin_time'])}}"  name="begin_time"  class="form-control datetimepicker">
                                                                </div>
                                                                <div class="col-sm-1">至</div>
                                                                <div class="col-sm-5 service-charges-remark service-charges-remark-0">
                                                                    <input type="text" placeholder="结束时间" value="{{date('Y-m-d H:i:s',$triggerData['end_time'])}}"  name="end_time" class="form-control datetimepicker">
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <!--触发次数-->
                                                    <div class="form-group">
                                                        <label class="col-sm-2 control-label">触发次数</label>
                                                        <div class="col-sm-7">
                                                            <div class="row">
                                                                {{--<div class="form-group">--}}
                                                                    <label class="sr-only col-sm-2" for="exampleInputAmount">触发次数</label>
                                                                    <div class="input-group col-sm-10">
                                                                        <div class="input-group-addon">每人可触发</div>
                                                                        <input type="number" class="form-control" min="0" id="touchNumbers" value="{{$triggerData['trigger_times']}}" name="trigger_times" placeholder="请输入次数"/>
                                                                        <div class="input-group-addon">
                                                                            <select class="valid" name="trigger_times_unit">
                                                                                <option value="1" @if($triggerData['trigger_times_unit'] == 1) selected @endif>次/活动全程</option>
                                                                                <option value="2" @if($triggerData['trigger_times_unit'] == 2) selected @endif>次/活动每日</option>
                                                                            </select>
                                                                        </div>
                                                                    </div>
                                                                {{--</div>--}}
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <!--触发条件-->
                                                    <div class="form-group">
                                                        <label class="col-sm-2 control-label">触发条件</label>
                                                        <div class="col-sm-7">
                                                            <select class="form-control" name="trigger_condition">
                                                                <option value="{{\App\Models\ActivityTrigger\ActivityTrigger::ACTIVITY_TRIGGER_LOGIN}}" @if($triggerData['trigger_condition'] == \App\Models\ActivityTrigger\ActivityTrigger::ACTIVITY_TRIGGER_LOGIN) selected @endif >登录</option>
                                                                <option value="{{\App\Models\ActivityTrigger\ActivityTrigger::ACTIVITY_TRIGGER_REGISTER}}" @if($triggerData['trigger_condition'] == \App\Models\ActivityTrigger\ActivityTrigger::ACTIVITY_TRIGGER_REGISTER) selected @endif >注册</option>
                                                                <option value="{{\App\Models\ActivityTrigger\ActivityTrigger::ACTIVITY_TRIGGER_PAY}}" @if($triggerData['trigger_condition'] == \App\Models\ActivityTrigger\ActivityTrigger::ACTIVITY_TRIGGER_PAY) selected @endif >支付</option>
                                                                <option value="{{\App\Models\ActivityTrigger\ActivityTrigger::ACTIVITY_TRIGGER_START}}" @if($triggerData['trigger_condition'] == \App\Models\ActivityTrigger\ActivityTrigger::ACTIVITY_TRIGGER_START) selected @endif >启动</option>
                                                            </select>
                                                        </div>
                                                    </div>
                                                    <!--触发用户-->
                                                    <div class="form-group">
                                                        <label class="col-sm-2 control-label">触发用户</label>
                                                        <div class="col-sm-7">
                                                            <select class="form-control" name="target">
                                                                <option value="1" @if($triggerData['target'] == 1) selected @endif >所有用户</option>
                                                            </select>
                                                        </div>
                                                    </div>
                                                    <!--优先级-->
                                                    <div class="form-group">
                                                        <label class="col-sm-2 control-label">优先级</label>
                                                        <div class="col-sm-7">
                                                            <input type="text" name="weight"  value="{{$triggerData['weight']}}" class="form-control" placeholder="优先级" />
                                                        </div>
                                                    </div>


                                                </div>
                                            </div>

                                        </div>
                                    </div>

                                    <div class="footer pull-center">

                                        <button type="submit" class="btn btn-info btn-fill btn-wd btn-finish sponsor_sur">
                                            完成
                                        </button>

                                        <div class="clearfix"></div>
                                    </div>

                                </form>


                            </div>
                        </div>
                    </div>
                </div>
                <!-- Modal -->
                <div class="modal fade" id="touch-upload-modal" tabindex="-1" role="dialog">
                    <div class="modal-dialog" role="document">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                <h4 class="modal-title" id="touch-upload-modal-header">上传图片</h4>
                            </div>
                            <div class="modal-body">
                                <div class="row">
                                    <div class="col-sm-6 col-sm-offset-3">
                                        <input type="file" name="upfile" accept="image/gif,image/jpeg,image/png" data-target="uploadImageFile" data-for="img_url" data-preview-file-type="text" class="form-control" value="" title="">
                                        <input type="hidden" class="img_url"  name="img_url" value="" >
                                    </div>
                                </div>
                                {{--<div class="touch-modal-ico-list">--}}
                                {{--<ul class="touch-modal-ico-ul">--}}
                                {{--<li>--}}
                                {{--<div class="touch-upload-input" tooltip="直接上传">--}}
                                {{--<input type="file" class="touch-input-upload-file f30 text-center" accept=".jpg,.png,.jpeg,.gif"/>--}}
                                {{--<label class="text-center f30">+</label>--}}

                                {{--</div>--}}

                                {{--</li>--}}
                                {{--</ul>--}}
                                {{--</div>--}}
                                {{--</div>--}}
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                                    <button type="button" class="btn btn-primary touch-modal-sure">确定</button>
                                </div>
                            </div>
                        </div>
                    </div>
            </div>
        </div>
    </div>
</div>



@endsection
@section('script')
    <script src="/js/admin/activityTrigger/initTriggerActive.js"></script>
    <script>

        $(document).ready(function (e) {
            var smallimgsrc;
            var imgSelected=1; //图片选择事件，用于区分大小图片属性
            var smallStoryI="{{$triggerData['checked_small_img']}}".replace('alioss://','http://cloud-activity-test.oss-cn-shanghai.aliyuncs.com/');
            var bigStoryI="{{$triggerData['checked_big_img']}}".replace('alioss://','http://cloud-activity-test.oss-cn-shanghai.aliyuncs.com/');

            /*渲染数据库中存储的选中的图像
            * localStorage.setItem('testImgSS',changeSrc);
             localStorage.removeItem('testImgDS');*/
            if(smallStoryI){

                    console.log('edit small');
                    console.log('img[src='+smallStoryI+']');
                    $('.small-ico-ul .touch-small-ico-li').removeClass('touch-ico-border');
                    $('img[src="'+smallStoryI+'"]').closest('li').addClass('touch-ico-border');
                    console.log($('.touch-app-small-image').css('background'));
                    $('.touch-app-small-image').css({
                        'background':'url('+smallStoryI+')',
                        'background-size':'40px auto',
                        'left':305* (parseInt("{{$triggerData['toleft']}}")/100),
                        'top':414* (parseInt("{{$triggerData['totop']}}")/100)
                    });
                }else if(bigStoryI){
                    console.log('edit big');
                    $('.big-ico-ul .touch-small-ico-li').removeClass('touch-ico-border');
                    $('img[src="'+bigStoryI+'"]').closest('li').addClass('touch-ico-border');
                    $('.touch-app-big-image>img').attr('src',bigStoryI);
                }


            if($('input[type="radio"]:checked').val()=='1'){
                $('.touch-big-picture').addClass('displayable');
                $('.touch-small-picture').removeClass('displayable');
                $('.touch-app-big-image').addClass('displayable');
                $('.touch-app-small-image').removeClass('displayable');
                imgSelected = 1;
            }else{
                $('.touch-small-picture').addClass('displayable');
                $('.touch-big-picture').removeClass('displayable');
                $('.touch-app-small-image').addClass('displayable');
                $('.touch-app-big-image').removeClass('displayable');
                imgSelected = 2;
            }

            //图标样式选择
            $('.touch-put-small-picture').click(function () {
                $('.touch-big-picture').addClass('displayable');
                $('.touch-small-picture').removeClass('displayable');
                $('.touch-app-big-image').addClass('displayable');
                $('.touch-app-small-image').removeClass('displayable');
                imgSelected = 1;
            });
            $('.touch-put-big-picture').click(function () {
                $('.touch-small-picture').addClass('displayable');
                $('.touch-big-picture').removeClass('displayable');
                $('.touch-app-small-image').addClass('displayable');
                $('.touch-app-big-image').removeClass('displayable');
                imgSelected = 2;
            });
            $('.touch-put-no-picture').click(function () {
                $('.touch-app-big-image').addClass('displayable');
                $('.touch-app-small-image').addClass('displayable');
                $('.touch-small-picture').addClass('displayable');
                $('.touch-big-picture').addClass('displayable');
                imgSelected = 0;
            });

            //悬浮时间选择框
            $('.touch-select-float-time').change(function () {
                var selectval=$(this).val();
                if(selectval=='2' && $('.touch-input-float-time').hasClass('displayable')){
                    $('.touch-input-float-time').removeClass('displayable');
                }else if(!$('.touch-input-float-time').hasClass('displayable')){
                    $('.touch-input-float-time').addClass('displayable');
                }
            });
            //摸态框图像选择
            $('.touch-modal-sure').click(function () {
                smallimgsrc=$('.img_url').val();
                var img_id = new Date().getTime();
                if(imgSelected == 1) {
                    $('.touch-ico-add-small').before('<li class="touch-small-ico-li">' +
                        '<img id="' + img_id + '" src="">' +
                        '</li>');
                    $('.touch-ico-add-small').before('<input type="hidden" name="small_img[]" value="'+smallimgsrc+'" />');
                    var img_url = "http://cloud-activity-test.oss-cn-shanghai.aliyuncs.com/" + smallimgsrc.substr(8);
                    $("#" + img_id).attr("src", img_url);
                    $('.small-ico-ul .touch-small-ico-li').removeClass('touch-ico-border');
                    $(".touch-small-ico-li>img[id='"+img_id+"']").closest('.touch-small-ico-li').addClass('touch-ico-border');
//                    $("#" + img_id).closest("touch-small-ico-li").addClass('touch-ico-border');
                    $('.touch-app-small-image').css({
                        'background':'url('+img_url+')',
                        'background-size':'40px auto'
                    });

                }else if(imgSelected == 2) {
                    $('.touch-ico-add-big').before('<li class="touch-small-ico-li">' +
                        '<img id="' + img_id + '" src="">' +
                        '</li>');
                    $('.touch-ico-add-big').before('<input type="hidden" name="big_img[]" value="'+smallimgsrc+'" />');
                    var img_url = "http://cloud-activity-test.oss-cn-shanghai.aliyuncs.com/" + smallimgsrc.substr(8);
                    $("#" + img_id).attr("src", img_url);
                    $('.big-ico-ul .touch-small-ico-li').removeClass('touch-ico-border');
                    $(".touch-small-ico-li>img[id='"+img_id+"']").closest('.touch-small-ico-li').addClass('touch-ico-border');
//                    $("#" + img_id).closest(".touch-small-ico-li").addClass('touch-ico-border');
                    $('.touch-app-big-image>img').attr('src',img_url);
                }
                initImgTouch();
                $('#touch-upload-modal').modal('hide');
            });

            //小图拖拽
            $( ".touch-app-small-image" ).draggable({ containment: ".touch-app-small-moveDiv", scroll: false });
            $( ".touch-app-small-image" ).draggable({
                start: function() {
                },
                drag: function(event,ui) {
                    $('.touch-app-small-image').css('left',ui.position.left);
                    $('.touch-app-small-image').css('top',ui.position.top);
                    var toleft=Math.round(ui.position.left/ 305 * 100);
                    var totop=Math.round(ui.position.top/ 414 * 100);
                    $('.touch-ico-top').empty();
                    $('.touch-ico-top').html(totop);
                    $('.totop').val(totop);
                    $('.touch-ico-left').empty();
                    $('.touch-ico-left').html(toleft);
                    $('.toleft').val(toleft);
                },
                stop: function(event,ui) {
//                    console.log(ui.offset.left,'ui.offset.left');
//                    console.log(ui.offset.top,'ui.offset.top');
//                    console.log(ui.position.left,'ui.position.left');
//                    console.log(ui.position.top,'ui.position.top');
                }
            });
            //图像类型图像点击
            $('.touch-small-ico-li').click(function () {
                var changeSrc=$(this).children('img')[0].src.replace('http://cloud-activity-test.oss-cn-shanghai.aliyuncs.com/','alioss://');
                var changeSrcP=$(this).children('img')[0].src;
                if($('input[type="radio"]:checked').val()=='1'){
                    $(".checked_small_img").val(changeSrc);
                    $('.small-ico-ul .touch-small-ico-li').removeClass('touch-ico-border');
                    $('.touch-app-small-image').css({
                        'background':'url('+changeSrcP+')',
                        'background-size':'40px auto'
                    });
                }else{
                    $(".checked_big_img").val(changeSrc);
                    $('.big-ico-ul .touch-small-ico-li').removeClass('touch-ico-border');
                    $('.touch-app-big-image>img').attr('src',changeSrcP);
                }
                $(this).addClass('touch-ico-border');
            });

        });

        function categoryFormatter(value,row) {
            return row.model.name;
        }
        var globObj;
        window.operateEvents = {
            'click .selectTrigger':function (e,value,row) {
                //给选择框设置数据
                $(globObj).val(row.name);
                $(globObj).prev().val(row.id);
            }
        };
        function actType(obj){
            var act_type = $(obj).data('val');
            var oo =$(obj).parent().parent().prev();
            oo.val(act_type);//设置数值
            if(act_type == "{{\App\Models\ActivityTrigger\ActivityTrigger::ACTIVITY_TRIGGER_ACT_TYPE_LIST}}"){
                oo.prev().text('列表活动');
                $('input[aria-label="添加活动"]').attr('placeholder','+添加活动');
            }else{
                $('input[aria-label="添加活动"]').attr('placeholder','请输入活动地址：(示例) http://');
                oo.prev().text('自有活动');
            }
        }
        function operateFormatter(value, row) {
            return '<a class="btn btn-warning btn-fill selectTrigger">选取</a>';
        }
        function show_activity_deliveries(obj) {
            globObj = obj;
            var vv = $(obj).next().children('input[data-name="act_type"]').val();
            // 判断：1-列表活动  2-自有活动
            if(vv == 1) {
                $addprize = utils.modal('选择活动', function (ele) {
                    var category = $('input[name="category"]').val();
                    var html = '<table class="table-responsive" id="activitySelectTable">' +
                        '<thead><tr>' +
                        '<th data-field="name">活动名称</th>' +
                        '<th data-field="model.name" data-formatter="categoryFormatter">类型</th>' +
                        '<th data-field="created_at">创建时间</th>' +
                        '<th data-field="startTime">有效期</th>' +
                        '<th data-field="actions" class="td-actions text-center" data-events="operateEvents" data-formatter="operateFormatter">操作</th>' +
                        '</tr></thead>' +
                        '</table>';
                    ele.find('.modal-body').html(html);
                    var table_option = {
                        searchAlign: 'left',
                        queryParams: function (query) {
                            query['category'] = 2;
                            return query;
                        },
                        url: '/web/activity/list'
                    };
                    default_table_option = $.extend(default_table_option, table_option);
                    $('#activitySelectTable').bootstrapTable(default_table_option);
                    $('#activitySelectTable').on('click', '.selectTrigger', function () {
                        $addprize.modal('hide');
                    })
                }, false, function (res) {
                    if (res == 1) {
                        $addprize.modal('hide');
                    }
                })
            }
        }
        <!--表单验证-->
        function beforeSubmitValidate() {
            var checkedPlatform = $("input:checkbox[name='platform[]']:checked").length;//选择平台
            var type = $("input:radio[name='show_img']:checked").length;//触发形式
            var name = $('input[name="rule_name"]').val();//规则名称
            name = name.trim();
            var float_time = $('input[name="float_time"]').val();//悬浮时间
            //触发时间
            var begin_time = $('input[name="begin_time"]').val();
            var end_time= $('input[name="end_time"]').val();
            var start=moment(begin_time).unix();
            var end=moment(end_time).unix();
            //触发次数
            var trigger_times=$('input[name="trigger_times"]').val();
            //优先级
            var trigger_weight=$('input[name="weight"]').val();
            //添加活动
            var addAction=$('input[name="act_name"]').val();
            var actionType=$('input[name="act_type"]').val();
            var ts=/^((https|http)?:\/\/)[^\s]+/;


            if(name == ''){
                utils.showNotification('规则名称不能为空',3);
                return false;
            }else if(name.length>20){
                utils.showNotification('规则名称不能大于20个字符集',3);
                return false;
            }

            if(checkedPlatform == 0){
                utils.showNotification('请选择平台',3);
                return false;
            }
            if(type == 0){
                utils.showNotification('请选触发形式',3);
                return false;
            }
            if(!addAction){
                utils.showNotification('请添加投放活动', 3);
                return false;
            }else if(addAction&&actionType==2&&!ts.test(addAction)){
                utils.showNotification('请添加正确的投放活动地址，如：http://', 3);
                return false;
            }
            if($('.touch-select-float-time').val==2&&(!float_time||parseInt(float_time)<1)){
                utils.showNotification('请添加不小于1秒的悬浮时间', 3);
                return false;
            }
            if (!begin_time||!end_time){
                utils.showNotification('请选择触发时间',3);
                return false;
            }else if(start>end) {
                utils.showNotification('开始时间不能大于结束时间', 3);
                return false;
            }
            if(!trigger_times){
                utils.showNotification('请输入触发次数', 3);
                return false;
            }
            if(!trigger_weight){
                utils.showNotification('请填入触发优先级', 3);
                return false;
            }

            return true;
        }

    </script>

@endsection